// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
         wx.showLoading({
          title: '加载中',
          mask: true
        });
        wx.request({
          url: this.globalData.api + '/users/wechat',
          method: 'POST',
          data: {
            code: res.code
          },
          success: (result) => {
            wx.hideLoading();
            wx.setStorageSync('openId', result.data.openId);
          }
      })
      }
    })
  },
  globalData: {
    userInfo: null,
    api:"http://localhost:4021/api",
    pointsapi: "http://localhost:4021/api/points",
    momentsapi:"http://localhost:4021/api/moments",
    usersapi:"http://localhost:4021/api/users",
    imageUrl: "http://localhost:4021/images/"
  }
})
